package com.fivefu.core.hillstone.controller;

import com.fivefu.base.web.controller.BaseController;
import com.fivefu.base.web.vo.ResultInfo;
import com.fivefu.core.hillstone.services.HillstoneService;
import com.fivefu.core.hillstone.services.OrganizationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Api(tags = "基础功能")
@RestController
@RequestMapping("/dahua")
public class OrganzationController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(OrganzationController.class);

    @Autowired
    private OrganizationService organizationService;

    @Autowired
    private HillstoneService hillstoneService;

    @ApiOperation(value = "获取所有组织架构",httpMethod = "POST",response = ResultInfo.class,notes = "获取所有组织架构")
    @RequestMapping(path = "/getOrganizationalStructure",method = RequestMethod.POST)
    public ResultInfo getOrganizationalStructure() {
        try {
            //调用登录
            hillstoneService.login();
            organizationService.queryOrganizaitonList(null);
            //销毁会话
            hillstoneService.destoryToken();
            return ResultInfo.renderSuccess("获取所有组织架构获取所有组织架构成功");
        } catch (Exception e) {
            logger.error("获取所有组织架构出现异常：" + e.getMessage(),e);
            return ResultInfo.renderError("获取所有组织架构失败");
        }
    }

    @ApiOperation(value = "获取所有设备通道",httpMethod = "POST",response = ResultInfo.class,notes = "获取所有设备通道")
    @RequestMapping(path = "/getChannelDevices",method = RequestMethod.POST)
    public ResultInfo getChannelDevices() {
        try {
            //调用登录
            hillstoneService.login();
            organizationService.getChannelDevices();
            //销毁会话
            hillstoneService.destoryToken();
            return ResultInfo.renderSuccess("获取所有设备通道成功");
        } catch (Exception e) {
            logger.error("获取所有设备通道出现异常：" + e.getMessage(),e);
            return ResultInfo.renderError("获取所有设备通道失败");
        }
    }

    @ApiOperation(value = "完善设备节点信息",httpMethod = "POST",response = ResultInfo.class,notes = "完善设备节点信息")
    @RequestMapping(path = "/queryEquipmentInfoByDeviceCode",method = RequestMethod.POST)
    public ResultInfo queryEquipmentInfoByDeviceCode() {
        try {
            organizationService.queryEquipmentInfoByDeviceCode();
            return ResultInfo.renderSuccess("完善设备节点信息成功");
        } catch (Exception e) {
            logger.error("完善设备节点信息出现异常：" + e.getMessage(),e);
            return ResultInfo.renderError("完善设备节点信息失败");
        }
    }
}
